package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Teacher t = new Teacher();
        t.name = "范传奇";
        t.age = 18;
        System.out.println(t);
        Class cls =  Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();


        Field field = cls.getField("name");
        field.set(obj,"苍老师");

        Field field1 = cls.getField("age");
        field1.set(obj,20);

        System.out.println(obj);

        Object v= field.get(obj);//String n = obj.name
        System.out.println(v);
        System.out.println(field1.get(obj));

    }
}
